﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CvModel;
using System.Data.Entity.Migrations;
using System.Data.SqlClient;
using System.Data;

namespace DAL
{
    public class ContactPersonDB
    {
        private static CvModelContainer _context = new CvModelContainer();

        //CREATE
        public static int CreateContactPerson(ContactPerson contactPerson)
        {
            try
            {
                var query = _context.ContactPersons.Add(contactPerson);
                return _context.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }
        //READ
        public static ContactPerson GetContactPerson(int contactPersonId)
        {
            try
            {
                return _context.ContactPersons.Where(c => c.ContactPersonId == contactPersonId).ToList().First();
            }
            catch (Exception)
            {

                throw;
            }
        }
        //UPDATE
        public static int UpdateContactPerson(ContactPerson contactPerson)
        {
            try
            {
                _context.ContactPersons.AddOrUpdate(contactPerson);
                return _context.SaveChanges();
            }
            catch (Exception)
            {

                throw;
            }
        }
        //DELETE
        public static int DeleteContactPerson(int contactPersonId)
        {
            try
            {
                var query =
                    (from c in _context.ContactPersons
                     where c.ContactPersonId == contactPersonId
                     select c).Single();

                _context.ContactPersons.Remove(query);

                return _context.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
